#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<errno.h>

int main()
{
    //创建socket对象
    int sockfd=socket(AF_INET6,SOCK_DGRAM,0);

    //创建网络通信对象
    struct sockaddr_in6 addr;
    addr.sin6_family =AF_INET6;
    addr.sin6_port =htons(1324);
    if (inet_pton(AF_INET6, "::1", &addr.sin6_addr) <= 0) {
        fprintf(stderr, "inet_pton error: %d(%s)", errno, strerror(errno));
	return 1;
    }


    //绑定socket对象与通信链接
    int ret =bind(sockfd,(struct sockaddr*)&addr,sizeof(addr));
    if(0>ret)
    {
        printf("bind\n");
        return -1;
    }
    struct sockaddr_in cli;
    socklen_t len=sizeof(cli);

    char buf =0;
    recvfrom(sockfd,&buf,sizeof(buf),0,(struct sockaddr*)&cli,&len);
    printf("recv num =%hhd\n",buf);

    close(sockfd);
}
